/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fasea.search.documents;

import fasea.utils.FileUtil;
import java.io.File;
import java.text.DateFormat;

/**
 *
 * @author WolframL
 */
public class FolderDocument extends Document {

    public FolderDocument(org.apache.lucene.document.Document document) {
        setDocument(document);
    }

    @Override
    public String getFragment() {
        StringBuilder fragmentBuilder = new StringBuilder();
        String lastModified = DateFormat.getDateInstance().format(getLastModified());
        File file = new File(getPath());
        File[] files = file.listFiles();
        int filesNumber = files.length;
        int foldersNumber = 0;

        for (int i = 0; i < filesNumber; ++i) {
            if (FileUtil.isDirectory(files[i])) {
                filesNumber--;
                foldersNumber++;
            }
        }

        fragmentBuilder.append("<font face=\"arial,sans-serif\" size=\"4\" color=\"#96b1cb\">");
        fragmentBuilder.append("Contains ").append(filesNumber).append(" files, ").append(foldersNumber).append(" folders. ");
        fragmentBuilder.append("Last Modified: ").append(lastModified);
        fragmentBuilder.append("</font>");
        return fragmentBuilder.toString();
    }
}
